#include <iostream>
#include <memory>
#include <vector>
using namespace std;
//责任链设计模式 

class TaskList
{
	public:
	TaskList()
	:flag(true)
	{
	}
	bool IsEnable()
	{
		return flag;
	}
	void Enable()
	{
		flag = true;
	}
	void DisEnable()
	{
		flag = false;
	}
	void SetTaskList(shared_ptr<TaskList> tasklist)
	{
		nextptr = tasklist;
	}
	virtual void Execute(vector<int>&) = 0;
	protected:
	bool flag;
	shared_ptr<TaskList> nextptr;
};
class AddTask : public TaskList
{
	public:
	virtual void Execute(vector<int>& v) override	
	{
		if(flag)
		{
			cout << "执行AddTask" << endl;
			for(auto& e : v){
			e += 1;
		}
		}
		if(nextptr){
			nextptr->Execute(v);
		}
		else{
			cout << "到达责任链处理结尾，完成责任链处理" << endl; 
		}
	}
};
class MultiTask : public TaskList
{
	public:
	virtual void Execute(vector<int>& v)	override
	{
		if(flag)
		{
			for(auto& e : v){
			e *= 3; 
		}
		cout << "执行MultiTask" << endl;
		}
		if(nextptr){
			nextptr->Execute(v);
		}
		else{
			cout << "到达责任链处理结尾，完成责任链处理" << endl; 
		}
	}
};

class Task
{
	public:
		Task()
		{
			addtask = make_shared<AddTask>();
			multitask = make_shared<MultiTask>();
			addtask->SetTaskList(multitask);
		}
	void Run(vector<int>& v)
	{
		addtask->Execute(v);
	}
	private:
		shared_ptr<TaskList> addtask;
		shared_ptr<TaskList> multitask;
};

int main()
{
	vector<int> v = {1,1};
	Task().Run(v);
	return 0;
}